<?php // 4.0
class showcustomer {
  function loaddata() {
    global $masterclass;

    $masterclass->loadmodule('customers');
    $masterclass->loadmodule('personnel');
    $masterclass->loadmodule('invoices');
    
    $masterclass->loadmodule('customers_wap',$masterclass->mainconfig['moduledirectory'].'customers/customers_wap.func.php');
    $masterclass->loadmodule('invoices_wap',$masterclass->mainconfig['moduledirectory'].'invoices/invoices_wap.func.php');
    
    
    if (!isset($masterclass->sitevars['customerid']) || $masterclass->sitevars['customerid']=='') {
      echo 'Customer Does Not Exist';
      exit();
    }
    
    $masterclass->site['postfields'][] = array(
      'table'=>'customers',
      'trackingid'=>'customerid',
      'fields'=>array(

        'first'=>'customers_customerfirst',
        'last'=>'customers_customerlast',
        'spouse'=>'customers_customerspouse',
        'company'=>'customers_customercompany',
        'emaila'=>'customers_customeremaila',
        'emailb'=>'customers_customeremailb',
        'dayphone'=>'customers_customerdayphone',
        'dayphoneext'=>'customers_customerdayphoneext',
        'nightphone'=>'customers_customernightphone',
        'nightphoneext'=>'customers_customernightphoneext',
        'otherphonea'=>'customers_customerotherphonea',
        'otherphoneaext'=>'customers_customerotherphoneaext',
        'otherphoneb'=>'customers_customerotherphoneb',
        'otherphonebext'=>'customers_customerotherphonebext',
        'fax'=>'customers_customerfax',
        'address'=>'customers_customeraddress',
        'apt'=>'customers_customerapt',
        'city'=>'customers_customercity',
        'state'=>'customers_customerstate',
        'zip'=>'customers_customerzip',

        'personnel'=>'customers_salesperson'
      ),
      'static'=>array(
        'active'=>'1'
      )
    );
    
  return;
  }

  function savedata() {
    global $masterclass;
    
  return;
  }


  function display() {
  global $masterclass;

  echo '<a href="'.$masterclass->mainconfig['dir'].$masterclass->mainconfig['htmldirectory'].'">Home</a> | <a href="'.$masterclass->mainconfig['dir'].$masterclass->mainconfig['htmldirectory'].'invoices/">Invoices</a> | <a href="'.$masterclass->mainconfig['dir'].$masterclass->mainconfig['htmldirectory'].'customers/">Customers</a><hr>';

  echo '<b>'.$masterclass->sitevars['customers_customerfirst'].' '.$masterclass->sitevars['customers_customerlast'].'</b><br>';

  if ($masterclass->sitevars['customers_customerspouse']!='') echo 'Spouse: <b>'.$masterclass->allclasses['websites']->disp_text('customers_customerspouse').'</b><br>';
  if ($masterclass->sitevars['customers_customercompany']!='') echo 'Company: <b>'.$masterclass->allclasses['websites']->disp_text('customers_customercompany').'</b><br>';
  if ($masterclass->sitevars['customers_customeremaila']!='') echo 'Email: <b>'.$masterclass->allclasses['websites']->disp_text('customers_customeremaila').'</b><br>';
  if ($masterclass->sitevars['customers_customeremailb']!='') echo 'Email: <b>'.$masterclass->allclasses['websites']->disp_text('customers_customeremailb').'</b><br>';
  if ($masterclass->sitevars['customers_customerdayphone']!='') echo 'D.Phone: <b>'.$masterclass->allclasses['websites']->disp_text('customers_customerdayphone').'</b><br>';
  if ($masterclass->sitevars['customers_customernightphone']!='') echo 'N.Phone: <b>'.$masterclass->allclasses['websites']->disp_text('customers_customernightphone').'</b><br>';
  if ($masterclass->sitevars['customers_customerotherphonea']!='') echo 'Phone: <b>'.$masterclass->allclasses['websites']->disp_text('customers_customerotherphonea').'</b><br>';
  if ($masterclass->sitevars['customers_customerotherphoneb']!='') echo 'Phone: <b>'.$masterclass->allclasses['websites']->disp_text('customers_customerotherphoneb').'</b><br>';
  if ($masterclass->sitevars['customers_customerfax']!='') echo 'Fax: <b>'.$masterclass->allclasses['websites']->disp_text('customers_customerfax').'</b><br>';
  if (
    $masterclass->sitevars['customers_customeraddress']!='' ||
    $masterclass->sitevars['customers_customerapt']!='' ||
    $masterclass->sitevars['customers_customercity']!='' ||
    $masterclass->sitevars['customers_customerstate']!='' ||
    $masterclass->sitevars['customers_customerzip']!=''
  ) {
    echo 'Address<br>';
  } 
  if ($masterclass->sitevars['customers_customeraddress']!='') echo '<b>'.$masterclass->allclasses['websites']->disp_text('customers_customeraddress').'</b><br>';
  if ($masterclass->sitevars['customers_customerapt']!='') echo '<b>'.$masterclass->allclasses['websites']->disp_text('customers_customerapt').'</b><br>';
  if ($masterclass->sitevars['customers_customercity']!='') echo '<b>'.$masterclass->allclasses['websites']->disp_text('customers_customercity').'</b><br>';
  if ($masterclass->sitevars['customers_customerstate']!='' || $masterclass->sitevars['customers_customerzip']!='') echo '<b>'.$masterclass->allclasses['websites']->disp_text('customers_customerstate').', '.$masterclass->allclasses['websites']->disp_text('customers_customerzip').'</b><br>';
  
  echo '<br><center><b>Invoices</b></center><br>';
  
  $strwhere=sprintf(" (`active`='1') AND (`customer`=%d) ",$masterclass->allclasses['mysql_functions']->formatmysqldbl($masterclass->sitevars['customerid']));
  $listarray=$masterclass->fetch_records('invoices_documents','',$strwhere,' `documentid` DESC ');
  for ($i=0;$i<count($listarray);$i++) {
    $invoicetotals=$masterclass->allclasses['invoices']->fetch_invoices_totals($listarray[$i]['id']);
    if (!empty($invoicetotals)) { $listarray[$i]=array_merge($listarray[$i],$invoicetotals); }
  }
  $listdata=$masterclass->allclasses['invoices_wap']->display_invoices($listarray,$masterclass->mainconfig['dir'].$masterclass->mainconfig['htmldirectory'].'invoices/invoice.php?'.$masterclass->trackingvar_query().'&invoicesid=');
  echo $listdata['load_list'];
  
  echo '<br><center><b>Payments</b></center><br>';
  
  $listarray=array();
  $listdata=$masterclass->allclasses['customers_wap']->display_customerpayments($listarray,$masterclass->mainconfig['dir'].$masterclass->mainconfig['htmldirectory'].'payments/showpayment.php?'.$masterclass->trackingvar_query().'paymentid=');
  echo $listdata['load_list'];
  
  echo '<br><center><b>Customer Notes</b></center><br>';

  $customers_customernotes=$masterclass->allclasses['customers']->fetch_customernotes();
  echo $masterclass->displayhtmlvalue($customers_customernotes[0]['notes'],4);
  
  return;
  }
}
?>